package com.skplanet.oneplusonewindow.moimserver.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "MOIM_MOIM")
public class Moim_Moim  implements Serializable{

	public List<Moim_Plaza> getPlazas() {
		return plazas;
	}

	public void setPlazas(List<Moim_Plaza> plazas) {
		this.plazas = plazas;
	}
	
	public void addPlaza(Moim_Plaza plaza) {
		if(this.plazas == null) {
			this.plazas = new ArrayList<Moim_Plaza>();
		}
		this.plazas.add(plaza);
	}
	
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@Column(name = "content")
	private String content;

	@Column(name = "title")
	private String title;

	@OneToMany(mappedBy = "moim", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("id ASC" )
	private List<Moim_Member> members;
	
	@OneToMany(mappedBy = "moim2", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("id ASC" )
	private List<Moim_Plaza> plazas;
	
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinColumn(name = "user_id")
	@JsonIgnore
	private List<Moim_User> users;
	
	@Column(name = "coverNum")
	private int coverNum;
	

	public int getCoverNum() {
		return coverNum;
	}

	public void setCoverNum(int coverNum) {
		this.coverNum = coverNum;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<Moim_User> getUsers() {
		return users;
	}

	public void setUsers(List<Moim_User> users) {
		this.users = users;
	}
	
	public void addUser(Moim_User user) {
		if(this.users == null) {
			this.users = new ArrayList<Moim_User>();
		}
		this.users.add(user);
	}
	
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List<Moim_Member> getMembers() {
		return members;
	}

	public void setMembers(List<Moim_Member> members) {
		this.members = members;
	}
	public void addMember(Moim_Member member) {
		if(this.members == null)
			this.members = new ArrayList<Moim_Member>();
		this.members.add(member);
	}
	public void deleteMember(Moim_Member member) {
		if(this.members != null)
			this.members.remove(member);
	}
	
}
